/**
 * 
 */
package fr.gfi.agraf.vue.action.administrer.perimetre;

import java.util.Date;

import fr.gfi.agraf.service.IPerimetreService;
import fr.gfi.agraf.service.enumeration.EtatEnum;
import fr.gfi.agraf.utils.SpringFactory;
import fr.gfi.agraf.vue.action.AbstractApplicationSupportAction;
import fr.gfi.agraf.vue.bean.EtatDTO;
import fr.gfi.agraf.vue.bean.PerimetreDTO;

/**
 * @author Fw
 * 
 */
public class AjouterPerimetreAction extends AbstractApplicationSupportAction {

	/**
	 * Généré par Java
	 */
	private static final long serialVersionUID = 3848398595204424679L;

	private static final String PERIMETRE_SERVICE = "PerimetreService";

	private String libelle;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * fr.gfi.agraf.vue.action.AbstractApplicationSupportAction#executeAction()
	 */
	@Override
	public String executeAction() throws Exception {
		if (libelle.isEmpty()) {
			return ERROR;
		}

		final PerimetreDTO perimetreDTO = new PerimetreDTO();
		perimetreDTO.setDateCreation(new Date());
		final EtatDTO etat = new EtatDTO();
		etat.setId(EtatEnum.CREE.getId());
		perimetreDTO.setEtatDTO(etat);
		perimetreDTO.setLibelle(libelle);

		// Appel au service
		final IPerimetreService perimetreService = (IPerimetreService) SpringFactory.getApplicationContext()
				.getBean(PERIMETRE_SERVICE);
		perimetreService.ajouterPerimetre(perimetreDTO, getUtilisateurConnecte().getId());

		return SUCCESS;
	}

	/**
	 * @return the libelle
	 */
	public String getLibelle() {
		return libelle;
	}

	/**
	 * @param libelle
	 *            the libelle to set
	 */
	public void setLibelle(final String libelle) {
		this.libelle = libelle;
	}

}
